package caro.client.gui.templates;

import java.awt.Graphics;
import java.awt.Insets;
import java.net.URL;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.Border;

/**
 * Class MyTextField
 * @author Thanh Nhan
 * @Since Aug 28, 2011
 * @Version 1.0
 */
public class MyTextField extends JTextField{
    URL imgUrl;
    public MyTextField(URL imgUrl){
        this.imgUrl = imgUrl;
    }
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
	try {
            final java.awt.image.BufferedImage image = javax.imageio.ImageIO.read(imgUrl);
            Border border = UIManager.getBorder("TextField.border");
            JTextField defaultField = new JTextField();
            final int x = getWidth() - border.getBorderInsets(defaultField).right - image.getWidth();
            setMargin(new Insets(2, 2, 2, getWidth() - x));
            int y = (getHeight() - image.getHeight())/2;
            g.drawImage(image, x, y, this);
        } catch(Exception ignore) {}
    }
}
